package messages.data;

import java.util.ArrayList;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class CodeInjections {
	
	int startSize;
	
	public void runTests(ArrayList<String> codeInjection,
			int codeInjectionSize) {
		ArrayList<String> webElements = new ArrayList<String>();
		webElements.add("email");
		webElements.add("password");
		messagesCodeInjectionsTest(codeInjection, codeInjectionSize, webElements);
	}
	
	private void messagesCodeInjectionsTest(ArrayList<String> codeInjection,
			int codeInjectionSize, ArrayList<String> webElements) {
		
		WebDriver driver = new FirefoxDriver();
		driver.get("https://www.snapsation.com/login/");
		WebElement email = driver.findElement(By.name(webElements.get(0)));
		email.sendKeys("damciodamcio666@gmail.com");
		WebElement password = driver.findElement(By.name(webElements.get(1)));
		password.sendKeys("admin123admin");
		email.submit();
		driver.get("https://www.snapsation.com/profile/51addb062d68c05969210855");
		WebElement messageLink = driver.findElement(By.xpath("(//div[6]/div/a/span/span)"));
		messageLink.click();
		driver.get("https://www.snapsation.com/inbox/message/51b9d72b0e8ef5b842a8cb62");
		for(startSize = 0; startSize < codeInjectionSize; startSize++){
			WebElement messagesField = driver.findElement(By.xpath("(//form/div/input)"));
			messagesField.sendKeys(codeInjection.get(startSize));
			messagesField.submit();
		}
		
	}
}
